package com.genuine.hyjj.xml;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.util.Log;

import com.genuine.hyjj.bean.Express;
public class MyContentHandler extends DefaultHandler {
	 
	private List<Express> expresses;  
    public List<Express> getExpresses() {
		return expresses;
	}

	public void setExpresses(List<Express> expresses) {
		this.expresses = expresses;
	}


	private String preTAG;  
    private Express express;
	
	
	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		super.characters(ch, start, length);
		if(preTAG!=null)  
        {  
            String data=new String(ch, start, length);  
            if("time".equals(preTAG))  
            {  
                express.setTime(data);  
                Log.e("***********", data);
            }  
            else if("context".equals(preTAG))  
            {  
                express.setContent(data);  
                Log.e("***********", data);
            }  
        } 
	}

	@Override
	public void endDocument() throws SAXException {
		super.endDocument();	
		
	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		super.endElement(uri, localName, qName);
		if("data".equals(localName))  
        {  
            expresses.add(express);  
            express=null;  
        }  
        preTAG=null;
		 
	}

	@Override
	public void startDocument() throws SAXException {
		super.startDocument();
		expresses= new ArrayList<Express>();
		
	}
	
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		super.startElement(uri, localName, qName, attributes); 
        if("data".equals(localName)){
        	express= new Express();
        }
        preTAG=localName;
	}

	
	@Override
	public void startPrefixMapping(String prefix, String uri)
			throws SAXException {
		super.startPrefixMapping(prefix, uri);
	}
 
}
